#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"stack_element.h"
#include"stack.h"

int stack_element_creat(struct stack_element * elem,char * data){
    if(data==NULL) return -1;
    int data_len=strlen(data);
    elem=(struct stack_element *)malloc(sizeof(struct stack_element));
    elem->data=(char *)malloc(sizeof(char)*(data_len+1));
    elem->data=NULL;
    if(data_len>0){
        strcpy(elem->data,data);
        return 0;
    }else{
        return 0; 
}
}
void print_stsack_element(struct stack_element * elem){
    printf("\ndata:%s\tnext:%p\n",elem->data,elem->next);
}
struct stack *creat_stack(struct stack_element * elem){
    if(elem==NULL) return NULL;
    else if(elem->data==NULL) return NULL;
    struct stack * stack=(struct stack *)malloc(sizeof(struct stack));
    stack->head=elem;
    stack->tail=elem;
    stack->tail->next=NULL;
    stack->head=stack->tail;
    return stack;
}
struct stack_element * stack_element_create(char * data){
    if(data==NULL) return NULL;
    int data_len=strlen(data);
    struct stack_element * elem = (struct stack_element *)malloc(sizeof(struct stack_element));
    elem->data=(char *)malloc(sizeof(char)*(data_len+1));
    elem->next=NULL;
    if(data_len>0){
        strcpy(elem->data,data);
        return elem;
    }else{
        return elem;
    }
}

void print_stack_element(struct stack_element * elem){
    printf("\ndata:%s\tnext:%p\n",elem->data,elem->next);
}

int stack_element_delete(struct stack_element * elem){
    if(elem==NULL)return -1;
    free(elem->data);
    elem->data=NULL;
    elem->next=NULL;
    free(elem);
    return 0;
}
